package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 更新主密钥
 */
public class ChangeMainKey extends BasePopupView {
    Unbinder bind;
    @BindView(R.id.input_mainkey1)
    EditText inputMainkey1;
    @BindView(R.id.input_change_mainkey1)
    EditText inputChangeMainkey1;
    @BindView(R.id.input_mainkey2)
    EditText inputMainkey2;
    @BindView(R.id.input_change_mainkey2)
    EditText inputChangeMainkey2;
    @BindView(R.id.input_password_gztext)
    Button inputPasswordGztext;
    @BindView(R.id.input_password_outtext)
    Button inputPasswordOuttext;
    onChangeMainCallBacl mOnChangeMainCallBacl;

    public ChangeMainKey(@NonNull Context context, onChangeMainCallBacl onChangeMainCallBacl) {
        super(context);
        this.mOnChangeMainCallBacl = onChangeMainCallBacl;
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.change_main_key;
    }

    @OnClick({R.id.input_password_gztext, R.id.input_password_outtext})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.input_password_gztext:
                //确定
                if (inputMainkey1.getText().toString().equals("")) {
                    ToastUtils.showLong("请输入分量1");
                    return;
                }
//                if (inputChangeMainkey1.getText().toString().equals("")) {
//                    ToastUtils.showLong("请再次输入量1");
//                    return;
//                }
//                if (!inputMainkey1.getText().toString().equals(inputChangeMainkey1.getText().toString())) {
//                    ToastUtils.showLong("分量1输入不同！");
//                    return;
//                }
                if (inputMainkey2.getText().toString().equals("")) {
                    ToastUtils.showLong("请输入分量2");
                    return;
                }
//                if (inputChangeMainkey2.getText().toString().equals("")) {
//                    ToastUtils.showLong("请再次输入分量2");
//                }
//
//                if (!inputMainkey2.getText().toString().equals(inputChangeMainkey2.getText().toString())) {
//                    ToastUtils.showLong("分量2输入不同！");
//                    return;
//                }

                if (inputMainkey1.getText().toString().trim().length() != 32) {
                    ToastUtils.showLong("分量1输入长度错误！");
                    return;
                }
                if (inputMainkey2.getText().toString().trim().length() != 32) {
                    ToastUtils.showLong("分量2输入长度错误！");
                    return;
                }

                mOnChangeMainCallBacl
                        .onChangeMainok(inputMainkey1.getText().toString(), inputMainkey2.getText().toString());
                break;
            case R.id.input_password_outtext:
                //退出
                mOnChangeMainCallBacl.onChangeMainout();
                break;
        }
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);

    }

    public interface onChangeMainCallBacl {
        void onChangeMainok(String key1, String key2);

        void onChangeMainout();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

}
